package com.gz.steak.utils.jwt;

import com.auth0.jwt.JWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 刘牌
 * @Date 2020/3/20 0020 18:48
 * @Version 1.0
 */

public class TokenUtil {
    private final static Logger logger = LoggerFactory.getLogger(TokenUtil.class);
    /**
     * 根据token获取当前登陆的用户
     * @return
     */
    public static String getUser(HttpServletRequest request){
        return JWT.decode(request.getHeader("token")).getClaim("username").asString();
    }

    public static String getRoleId(HttpServletRequest request){
        return JWT.decode(request.getHeader("token")).getClaim("roleId").asString();
    }
}
